package com.mdlaser.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import com.mdlaser.annotation.CommonRest;
import com.mdlaser.api.ResponseResult;
import com.mdlaser.dto.LockedOrder;
import com.mdlaser.dto.OrderConsumeResult;
import com.mdlaser.dto.OrderDetail;
import com.mdlaser.dto.OrdersWishesDto;
import com.mdlaser.entity.OrdersWishes;
import com.mdlaser.enums.OrderStatusType;
import com.mdlaser.service.IOrderConsumer;
import com.mdlaser.service.IOrdersWishesService;
import com.mdlaser.sys.service.IUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author mdlaser
 * @since 2024-05-16
 */
@RestController
@RequestMapping("/others")
@Tag(name = "对外接口")
@Slf4j
public class ForOthonerController {

    @Autowired
    IOrdersWishesService ordersWishesService;

    @Operation(summary = "获取锁定订单", description = "获取锁定订单")
    @PostMapping("/getLockOrder")
    @SaIgnore
    public List<LockedOrder> getLockOrder() {
        return ordersWishesService.getLockOrder();
    }


    @Operation(summary = "上报播放状态", description = "上报播放状态")
    @PostMapping("/pushOrderStatus")
    @SaIgnore
    public String pushOrderStatus(@RequestBody OrderConsumeResult orderConsumeResult) {
        Integer orderId = orderConsumeResult.getTaskId();
        OrdersWishes ordersWishes = ordersWishesService.getBaseMapper().selectById(orderId);
        if (orderConsumeResult.getResult() == -1) {
            ordersWishesService.refund(orderId.toString(), "演出异常");
            ordersWishes.setOrderStatus(OrderStatusType.PLAYING_FAIL.getId());
        } else if (orderConsumeResult.getResult() == 1) {
            ordersWishes.setOrderStatus(OrderStatusType.PLAYING_SUCCESS.getId());
        }
        ordersWishesService.updateById(ordersWishes);
        return "success";
    }


}
